﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Reflection;
using MedicalSystem.SmartReport.Viewer;

namespace MedicalSystem.SamrtReport
{
    public partial class ReaderFrm : Form
    {
        #region Test Method
        private void MakeSomeTestData()
        {
            DataRow dr = this.DataSet.Tables["Employee"].NewRow();
            dr["ID"] = "0";
            dr["Name"] = "employee1";
            dr["Age"] = "22";
            dr["OrganizactionID"] = 1;
            this.DataSet.Tables["Employee"].Rows.Add(dr);

            DataRow dr1 = this.DataSet.Tables["Organizaction"].NewRow();
            dr1["OrganizactionID"] = "0";
            dr1["OrganizactionName"] = "Organizaction1";
            dr1["Leader"] = "leader1";
        
            DataRow dr2 = this.DataSet.Tables["Organizaction"].NewRow();
            dr2["OrganizactionID"] = "1";
            dr2["OrganizactionName"] = "Organizaction2";
            dr2["Leader"] = DBNull.Value;

            this.DataSet.Tables["Organizaction"].Rows.Add(dr1);
            this.DataSet.Tables["Organizaction"].Rows.Add(dr2);
            this.DataSet.AcceptChanges();
        }
        #endregion

        public DataSet _dataset=new DataSet();
        public DataSet DataSet
        {
            get { return _dataset; }
            set { _dataset = value; }
        }

        private string _fileName;

        public ReaderFrm(string fileName)
        {
            InitializeComponent();
            this._fileName = fileName;
            //_dataset.ReadXmlSchema(Application.StartupPath + @"\Data\DataSet.xml");

            //MakeSomeTestData();
        }

        private ReportViewer _reportViewer;
      
        private void FReader_Load(object sender, EventArgs e)
        {
            _reportViewer = new ReportViewer();
            _reportViewer.Dock = DockStyle.Fill;
            _reportViewer.DataSet = this.DataSet;
            _reportViewer.ReportClientId = "1";
            _reportViewer.BackColor = Color.White;
            this.panel1.Controls.Add(_reportViewer);

            _reportViewer.Preview(this._fileName);
         }
       


        private void ToolStripMenuItem_Click(object sender, EventArgs e)
        {
           // DataSet ds = new DataSet();
           // ds.ReadXmlSchema(Application.StartupPath + @"\Data\DataSet.xml");
           // DataRow dr = ds.Tables["Employee"].NewRow();
           // dr["ID"] = "0";
           // dr["Name"] = "employee2";
           // dr["Age"] = "22";
           // dr["OrganizactionID"] = 1;
           // ds.Tables["Employee"].Rows.Add(dr);
           
           //this.reportViewer1.DataSet = ds;
           //this.reportViewer1.DataBind();
           //// this.reportViewer1.EndCurrentEdit();
           //// DataSet ss = this.DataSet;
           //// this.reportViewer1.WriteToPdf(@"D:\1.pdf");
          // this.reportViewer1.Submit("0001");
           MessageBox.Show("表单已提交");
            //System.Diagnostics.Process.Start(@"D:\1.pdf");
            
        }

        private void 打印ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            _reportViewer.PrintPreview();
            //this.reportViewer1.Print();
        }

        private void 导出PdfToolStripMenuItem_Click(object sender, EventArgs e)
        {
            _reportViewer.WriteToPdf(@"D:\1.pdf");

            System.Diagnostics.Process.Start(@"D:\1.pdf");
        }
       
        
    }
}